﻿using System;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
using P2P_Backup.connections;

namespace P2P_Backup
{
    public class LocalPeer : Peer
    {
        
        public LocalPeerConnection connection;
        public UdpBroadcast broadcast;
        
        #region Singleton
        private static LocalPeer instance;
        public static LocalPeer Instance
        {
            get
            {
                if (instance == null) instance = new LocalPeer();
                return instance;
            }
        }
        #endregion
        
        private LocalPeer()
        {
            base.Hostname = Dns.GetHostName();
            foreach (IPAddress ipAddress in Dns.GetHostEntry(Dns.GetHostName()).AddressList)
            {
                if (ipAddress.AddressFamily == AddressFamily.InterNetwork)
                {
                    base.IpAddress = ipAddress;
                    break;
                }
            }
            IPEndPoint endPoint = new IPEndPoint(IPAddress.Any, P2PBackup.ApplicationPort);
            
            connection = new LocalPeerConnection(endPoint);
            broadcast = new UdpBroadcast(endPoint);
        }


        public void AddFileToArchive(archive.File file)
        {
            throw new NotImplementedException();
        }
    }
}
